﻿using System;
using System.Data;
using System.Configuration;
using HtmlAgilityPack;


/// <summary>
/// Summary description for GoldenPriceSJC
/// </summary>
/// 
/// 
namespace SJCGoldenPrice
{
public class GoldenPriceSJC : GoldenPrice
{
	public GoldenPriceSJC()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public  override void getPrice()
    {
        this.Hcm.Ban = "";
        this.LinkService = ConfigurationSettings.AppSettings["GoldPrice_WebService_SJC"].ToString().Trim();
        try
        {
           
                String Url = this.LinkService;
                String webHtml = WebTool.getWebContent(Url);

                if (webHtml != "")
                {
                    HtmlDocument doc = new HtmlDocument();
                    int posSJC10c = webHtml.IndexOf("Vàng SJC 1L");
                    webHtml = webHtml.Substring(posSJC10c);
                    doc.LoadHtml(webHtml);
                    
                    HtmlNodeCollection tdCol = doc.DocumentNode.SelectNodes("//td");

                    if (tdCol[0].InnerText != "")
                    {
                        Hcm.Mua = tdCol[0].InnerText;
                        Hcm.Ban = tdCol[1].InnerText.Replace("&nbsp;","");
                        Ha_noi.Mua = tdCol[37].InnerText;
                        Ha_noi.Ban = tdCol[38].InnerText.Replace("&nbsp;", "");
                        Da_nang.Mua = tdCol[42].InnerText;
                        Da_nang.Ban = tdCol[43].InnerText.Replace("&nbsp;", "");
                        Nha_trang.Mua = tdCol[47].InnerText;
                        Nha_trang.Ban = tdCol[48].InnerText.Replace("&nbsp;", "");
                        Can_tho.Mua = tdCol[52].InnerText;
                        Can_tho.Ban = tdCol[53].InnerText.Replace("&nbsp;", "");

                                              
                    }
                }
            
        }
        catch (Exception ex)
        {
            TLog.WriteErr("GoldenPriceSJC :getPrice", ex.ToString());

        }
        setNewValue();
    }
}
}